home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
569
/
rsctools
/
c_rsh.skl
next >
Wrap
Text File
|
1992-06-01
|
9KB
|
312 lines
/* This is a skeleton file for use with rsh.ttp and Lattice C 5.
*
* It replaces rsrc_load, rsrc_free, rsrc_gaddr, and optionally rsrc_saddr.
* I've never found the latter function useful, but if for some reason
* you need it, define the preprocessor symbol `MAKE_RSRC_SADDR'.
*
* Note that many types besides R_TREE, R_FRIMG, and R_FRSTR are defined
* for rsrc_gaddr and rsrc_saddr in the ROMs. However, these additional
* types aren't supported here, because they are in general quite useless,
* since existing RCS programs don't, for example, allow naming of TEDINFOs
* (you name the _object_, not the TEDINFO structure).
*
* Author: Doug Harrison
* Copyright (c) 1991 Doug Harrison.
*/
/* Lattice C 5 #defines several AES functions into direct calls to `_AESif'
* and any necessary setup code. I don't see any particular advantage to
* this (contrast to #pragma inline) in general, and since we're replacing
* functions that may be #defined, we must suppress this. The easiest
* way to accomplish this is to add a "#define __NO_AES_DEFINES" statement
* to the beginning of aes.h, which is what I recommend. Or, you could
* always add "-d__NO_AES_DEFINES" to your LC_OPT environment variable.
* Whatever you decide, be aware that you _must_ suppress the preprocessor
* redefinition of the functions this module replaces; otherwise, when your
* program references one of these functions, you will get the preprocessor
* definition and not the intended replacement!
*
* Here, we #define __NO_AES_DEFINES, and as long as it hasn't been #defined
* to a _value_ in LC_OPT or directly on the command line, there's no need
* to #undef it or see if it's already defined (ANSI permits redefinition
* of preprocessor symbols as long as all definitions are identical, down
* to whitespace).
*
* Note: I believe __NO_AES_DEFINES was added to Lattice 5.06, so if you're
* using an earlier version, you should make sure that aes.h is actually
* using this symbol, and if not, take whatever steps are necessary to
* ensure rsrc_load, etc. are not #defined (do something like add statements
* "#undef rsrc_load" to the end of aes.h for whatever functions we replace
* here).
*/
/* Note: since the original version, I've made some changes that allow
* this program to be compiled with Mark Williams C. Lattice C defines
* the symbol `LATTICE' automatically, so we use it for the conditional
* compilation. If LATTICE isn't defined, we assume a pre-ANSI C compiler
* and obdefs.h and gemdefs.h as the include files.
*/
#if defined LATTICE
#define __NO_AES_DEFINES
#include <aes.h>
/* Make sure none of the following are #defined in versions earlier than
* Lattice 5.06. You still need to take steps to ensure this in your other
* source files.
*/
#undef rsrc_load
#undef rsrc_free
#undef rsrc_gaddr
#undef rsrc_saddr
/* You may need to alter the following typedef... My aes.h uses unsigned
* long for the type of ob_spec, but the Lattice default is void *, so
* that's the default here as well.
*/
typedef void *ObSpecType;
#define VOID__ void
#define CONST__ const
#else
/* Since Lattice isn't defined, assume a pre-ANSI compiler. */
#include <obdefs.h>
#include <gemdefs.h>
typedef unsigned long ObSpecType;
/* VOID__ is our type for a void pointer. */
#define VOID__ char
#define CONST__
#endif
/* This type saves me some typing :-) */
typedef unsigned long ulong;
/* Convenient macros to return the OBJECT fields. */
#define OB_NEXT(tree,obj) ((tree)[obj].ob_next)
#define OB_HEAD(tree,obj) ((tree)[obj].ob_head)
#define OB_TAIL(tree,obj) ((tree)[obj].ob_tail)
#define OB_TYPE(tree,obj) ((tree)[obj].ob_type)
#define OB_STATE(tree,obj) ((tree)[obj].ob_state)
#define OB_FLAGS(tree,obj) ((tree)[obj].ob_flags)
#define OB_SPEC(tree,obj) ((tree)[obj].ob_spec)
#define OB_X(tree,obj) ((tree)[obj].ob_x)
#define OB_Y(tree,obj) ((tree)[obj].ob_y)
#define OB_W(tree,obj) ((tree)[obj].ob_width)
#define OB_H(tree,obj) ((tree)[obj].ob_height)
/* Rsh inserts its output by replacing the %% token. */
%%
/* Replacement functions follow. I've used old style C definitions for
* compatibility reasons, but since we've #included aes.h for Lattice C,
* our prototypes are in scope (this is critical when compiling with -rr).
*/
int
rsrc_load(name)
CONST__ char
*name;
{
int
i; /* Tracks the tree, object, free string, or free images. */
ulong
idx; /* Value of an entry in one of the index arrays, specific to
the entity we're considering. */
/* Only include the code we require (as far as we can determine, that
* is). Note that I've followed the DRI RCS lead of making the type of
* the index arrays long; of course, it should be unsigned long, since
* the indexes can never be negative (but this is admittedly being
* pedantic, since the indexes can never grow large enough to overflow
* a signed long).
*/
#if NUM_TREE
for (i = 0; i < NUM_TREE; i++)
rs_trindex[i] = (long) (rs_object+(ulong) rs_trindex[i]);
/* If we have some trees, it follows that we have some objects. */
for (i = 0; i < NUM_OBS; i++) {
/* Fix up object coordinates. */
rsrc_obfix(rs_object,i);
idx = (ulong) OB_SPEC(rs_object,i);
switch (OB_TYPE(rs_object,i) & 0xff) {
#if NUM_STRINGS
case G_STRING :
case G_BUTTON :
case G_TITLE :
OB_SPEC(rs_object,i) = (ObSpecType) rs_strings[idx];
break;
#endif
#if NUM_TI
case G_TEXT :
case G_BOXTEXT :
case G_FBOXTEXT :
case G_FTEXT : {
TEDINFO
*ted = rs_tedinfo+idx;
OB_SPEC(rs_object,i) = (ObSpecType) ted;
ted->te_ptext = rs_strings[(ulong) ted->te_ptext];
ted->te_ptmplt = rs_strings[(ulong) ted->te_ptmplt];
ted->te_pvalid = rs_strings[(ulong) ted->te_pvalid];
break;
}
#endif
#if NUM_BB
case G_IMAGE : {
BITBLK
*bb = rs_bitblk+idx;
OB_SPEC(rs_object,i) = (ObSpecType) bb;
bb->bi_pdata = rs_imdope[(ulong) bb->bi_pdata].image;
break;
}
#endif
#if NUM_IB
case G_ICON : {
ICONBLK
*ib = rs_iconblk+idx;
OB_SPEC(rs_object,i) = (ObSpecType) ib;
ib->ib_pmask = rs_imdope[(ulong) ib->ib_pmask].image;
ib->ib_pdata = rs_imdope[(ulong) ib->ib_pdata].image;
ib->ib_ptext = rs_strings[(ulong) ib->ib_ptext];
break;
}
#endif
default :
break;
}
}
#endif
#if NUM_FRSTR
/* This fixes up the array of pointers to free strings. */
for (i = 0; i < NUM_FRSTR; i++)
rs_frstr[i] = (long) (rs_strings[(ulong) rs_frstr[i]]);
#endif
#if NUM_FRIMG
/* This fixes up the array of pointers to free images (a free image is
* in actuality a BITBLK and is found in the `rs_bitblk' array).
*/
for (i = 0; i < NUM_FRIMG; i++) {
BITBLK
*bb = rs_bitblk+(ulong) rs_frimg[i];
rs_frimg[i] = (long) bb;
bb->bi_pdata = rs_imdope[(ulong) bb->bi_pdata].image;
}
#endif
/* We always win. */
return 1;
} /* rsrc_load */
int
rsrc_gaddr(type,index,p)
int
type,index;
VOID__
*p;
{
switch (type) {
#if NUM_TREE
case R_TREE :
*(OBJECT **) p = (OBJECT *) rs_trindex[index];
break;
#endif
#if NUM_FRSTR
case R_FRSTR :
*(char **) p = (char *) rs_frstr[index];
break;
#endif
#if NUM_FRIMG
case R_FRIMG :
*(BITBLK **) p = (BITBLK *) rs_frimg[index];
break;
#endif
default :
/* If we get here, an error occurred. So set `p' to NULL to
* cause a predictable bus error if the entity address is
* subsequently used.
*/
*(char **) p = (char *) 0;
return 0;
}
return 1;
} /* rsrc_gaddr */
int
rsrc_free()
{
/* We always win. */
return 1;
} /* rsrc_free */
#if defined MAKE_RSRC_SADDR
int
rsrc_saddr(type,index,p)
int
type,index;
VOID__
*p;
{
switch (type) {
#if NUM_TREE
case R_TREE :
rs_trindex[index] = (long) p;
break;
#endif
#if NUM_FRSTR
case R_FRSTR :
rs_frstr[index] = (long) p;
break;
#endif
#if NUM_FRIMG
case R_FRIMG :
rs_frimg[index] = (long) p;
break;
#endif
default :
return 0;
}
return 1;
} /* rsrc_saddr */
#endif